//
//  DDLoadingView.m
//  DingDongXiChe
//
//  Created by wtjr on 2018/1/2.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "CustomLoadingView.h"
#import "JQIndicatorView.h"

@interface CustomLoadingView()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) JQIndicatorView *indicator;

@end

@implementation CustomLoadingView

- (void)initSubViews {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubViews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    [self.mainView layoutIfNeeded];
}

#pragma mark - BaseMethod


#pragma mark - Interface

- (void)showLoading {
    self.indicator.backgroundColor = kCOLOR_white;
    self.indicator.center = CGPointMake(kUI_WIDTH/2 + 30, kUI_HEIGHT/2);
    self.mainView.alpha = 0.1;
    [kUI_Window addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    [UIView animateWithDuration:0.5 animations:^{
        self.mainView.alpha = 0.9;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)hideLoading {
    [UIView animateWithDuration:0.5 animations:^{
        self.mainView.alpha = 0.1;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

#pragma mark - Delegate


#pragma mark - TouchEvent


#pragma mark - Setter


#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        
        JQIndicatorView *indicator = [[JQIndicatorView alloc] initWithType:JQIndicatorTypeMusic1 tintColor:KCOLOR_lightFont];
        indicator.backgroundColor = kCOLOR_white;
        self.indicator = indicator;
        [_mainView addSubview:indicator];
        [indicator startAnimating];
        [indicator mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(@0);
            make.centerY.equalTo(@0);
            make.width.height.equalTo(@60);
        }];
    }
    return _mainView;
}

@end
